package com.zsrt.java.day20170112.lh.daily.ch01;

import static org.junit.Assert.*;

import java.io.File;
import java.util.Arrays;

import org.junit.Test;

public class FileTest {
	
	@Test
	public void FileTest() throws Exception {
		
		//两个斜杠 代表的是转义 \t table  \r\n换行
		File file=new File("c:/A.txt");//c:\\a.txt
		
		System.out.println(file.getName());;
		
		System.out.println(file.isFile());
		
		System.out.println(file.isDirectory());
		
		System.out.println(file.length());
		
	}
	
	/**
	 * 创建一个文件
	 * @throws Exception
	 */
	@Test
	public void createTemFile() throws Exception {
//		File file=File.createTempFile("bb", ".txt");
		File f=new File("c:aaa.txt");
		f.createNewFile();
		File f1=new File("c:aaa");
		f1.mkdirs();
		
		boolean e=f1.exists();
		System.out.println(e);
		
	}
	
	
	@Test
	public void canWirite() throws Exception {
		
		File ccc=new File("c:/aaa/a.txt");
		System.out.println(ccc.canExecute());
		System.out.println(ccc.canWrite());
		System.out.println(ccc.canRead());
		
		
		File c=new File("c:/aaa/c.txt");
		System.out.println(c.delete());
		
		
		File cc=new File("c:/aaa");
		
		String[] list = cc.list();
		System.out.println(Arrays.toString(list));
		
	
		
	}
	
	/**
	 * 创建一个多级目录文件
	 * @throws Exception
	 */
	@Test
	public void madirs() throws Exception {
		File cc=new File("c:/aaa/xx/oo/xxoo/a.txt");
		File parentFile = cc.getParentFile();
		if(!parentFile.exists()){
			
			parentFile.mkdirs();
		}
		cc.createNewFile();
		
	}
	
	@Test
	public void create() throws Exception {
		util.FlieUtil.createFile("c:/a/a/a/a/a/a/a/a.txt");
		
	}
	
	/**
	 * 相对路径
	 * @throws Exception
	 */
	@Test
	public void testName() throws Exception {
		
		
		util.FlieUtil.createFile("src/com/zsrt/java/day20170112/lh/daily/ch01/xxoo.txt");
	}
	

}
